﻿namespace Monadic.Tests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    
    /// <summary>
    ///This is a test class for IdentityTest and is intended
    ///to contain all IdentityTest Unit Tests
    ///</summary>
    [TestClass()]
    public class IdentityTests
    {

        [TestMethod]
        public void CreateIdentity()
        {
            var identity = Identity.Create(1);
            Assert.AreNotEqual(default(Identity<int>), identity);
        }
        
        [TestMethod]
        public void IdentityEquivilence()
        {
            var x = Identity.Create(1);
            var y = Identity.Create(1);
            Assert.AreEqual(x, y);
            Assert.AreNotSame(x, y);
        }

        [TestMethod]
        public void IdentityInequality()
        {
            var x = Identity.Create(1);
            var y = Identity.Create(2);
            Assert.AreNotEqual(x, y);
        }

        [TestMethod]
        public void IdentityIdentityProjectionEquivilence()
        {
            var x = Identity.Create(1);
            var y = x.Select(v => v);
            Assert.AreEqual(x, y);
            Assert.AreNotSame(x, y);
        }

        [TestMethod]
        public void IdentityNonIdentityProjectionInequality()
        {
            var x = Identity.Create(1);
            var y = x.Select(v => v + 1);
            Assert.AreNotEqual(x, y);
        }

        [TestMethod]
        public void SelectQuery()
        {
            var result = from x in Identity.Create(1)
                         select x.ToString();

            Assert.AreEqual("1", result.Value);
        }

        [TestMethod]
        public void SelectManyQuery()
        {
            var result = from x in Identity.Create(2)
                         from y in Identity.Create(3)
                         select x + y;

            Assert.AreEqual(5, result.Value);
        }
    }
}
